<template>
  <div class="table-container">
    <vab-query-form>
      <vab-query-form-left-panel>
        <el-button icon="el-icon-plus" type="primary" @click="handleAdd">
          添加
        </el-button>
      </vab-query-form-left-panel>
      <vab-query-form-right-panel>
        <el-form
          ref="form"
          :model="queryForm"
          :inline="true"
          @submit.native.prevent
        >
          <el-form-item>
            <el-input
              v-model="queryForm.keywords"
              placeholder="请输入姓名/手机号"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              icon="el-icon-search"
              type="primary"
              native-type="submit"
              @click="handleQuery"
            >
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      ref="tableSort"
      v-loading="listLoading"
      :data="list"
      :element-loading-text="elementLoadingText"
      :height="height"
      @selection-change="setSelectRows"
    >
      <el-table-column
        show-overflow-tooltip
        type="selection"
        width="55"
      ></el-table-column>
      <el-table-column show-overflow-tooltip label="序号" width="95">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip prop="nickname" label="姓名" class-name="nickname-image">
        <template #default="scope">
          <el-image
            :src="scope.row.avatar"
          ></el-image>
          <span style="margin-left: 10px">{{ scope.row.nickname }}</span>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="登录账号/手机号码"
        prop="phone"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="微信号"
        prop="weixin_id"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="身份角色"
        prop="role_name"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="账号备注"
        prop="description"
      >
      <template #default="scope">
        <span v-if="scope.row.description">{{scope.row.description}}</span>
        <span v-else class="description">无参数</span>
      </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="登录权限">
        <template #default="{ row }">
            <el-switch
            v-model="row.access"
            :disabled="row.role_name == '超级管理员' ? true : false"
            @change="changeAccess(row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="操作" width="180px">
        <template #default="{ row }">
          <el-button type="text" @click="handleEdit(row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :background="background"
      :current-page="queryForm.pageNo"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
  </div>
</template>
<script>
import { getUserList } from '@/api/accountSetting'
export default {
  components: {},
  data() {
    return {
      list: [],
      listLoading: true,
      layout: 'total, sizes, prev, pager, next, jumper',
      total: 0,
      background: true,
      selectRows: '',
      elementLoadingText: '正在加载...',
      queryForm: {
        pageNo: 1,
        pageSize: 10,
        keywords: '',
      },
    }
  },
  computed: {
    height() {
      return this.$baseTableHeight()
    },
  },
  created() {
    this.fetchData()
  },
  methods: {
    async fetchData() {
      this.listLoading = true
      const parms = {
        vehicle_users_gid: '59eFgUMYF9hqrRACqOBBM1v4prCwZN7K',
        page: this.queryForm.pageNo,
        list_row: this.queryForm.pageSize,
        keywords: '',
      }

      const { errCode, resData } = await getUserList(parms)
      // console.log(errCode, resData)
      this.list = resData.list
      this.total = resData.totalcount
      setTimeout(() => {
        this.listLoading = false
      }, 500)
    },
    handleAdd() {},
    handleQuery() {
      this.queryForm.pageNo = 1
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.queryForm.pageNo = val
      this.fetchData()
    },
    handleSizeChange(val) {
      this.queryForm.pageSize = val
      this.fetchData()
    },
    setSelectRows(val) {
      this.selectRows = val
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep .nickname-image .cell{
  display: flex;
  align-items: center;
}
.description{
  color:rgba(0, 0, 0, .25)!important;
}
</style>